e<template>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
        <el-form-item label="权限名称:">
            <el-input v-model="form.permissionName" />
        </el-form-item>

        <el-form-item label="权限URL:">
            <el-input v-model="form.permissionNo" />
        </el-form-item>

        <el-form-item label="权限序号:">
            <el-input v-model="form.permissionType" />
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="XiuInfo()">修改</el-button>
            <el-button type="info" @click="addInfo()">返回</el-button>
        </el-form-item>
    </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref,onMounted } from 'vue'

import { xieInfo } from '@/Http/axiosInfo'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import { useRoute } from 'vue-router'
const route = useRoute()
const router = useRouter()
// do not use same name with ref
const form = reactive({
    permissionId: 0,
    permissionType: '',
    "permissionNo": "",
    "permissionName": ""
})


const updainfo = async () => {
    let permissionId = route.query.PermissionId
    xieInfo.get('/Mang/Updatet', {
        params: {
            PermissionId: permissionId
        }
    })
        .then((res) => {
            console.log(res)
            form.permissionId = res.data.data[0].permissionId
            form.permissionType = res.data.data[0].permissionType
            form.permissionNo = res.data.data[0].permissionNo
            form.permissionName = res.data.data[0].permissionName
        })
}

const XiuInfo=()=>{
    xieInfo.put('/Mang/Xiu',form)
    .then((res)=>{
        console.log(res)
        if (res.data.code == 300) {
            ElMessage.success({
                message: '修改成功',
                type: 'success'
            })
        }
        router.push({ path: '/GetPermission' })
    })
}

const addInfo = () => {
    router.push({ path: '/GetPermission' })
}

onMounted(() => {
    updainfo()
})
</script>
